home *** CD-ROM | disk | FTP | other *** search
/ Developer CD Series 1992 June: ROMin Holiday / ADC Developer CD (1992-06) (''ROMin Holiday'')_iso / Developer Connection - 06-1992.iso / Tools & Apps / Testing & Debugging / Virtual User Libraries & Tools / Printing.lib 1.0 / Printing.lib
Encoding:
Text File  |  1992-05-08  |  15.9 KB  |  404 lines  |  [TEXT/MPS ]

  1. ##########################################################################
  2. ###################            Printing.lib        ##########################
  3. #=========================================================================
  4. #     Author:            O. Güracar
  5. #    Description:This library supports the most common settings for 
  6. #                Page Setup and Printing. You can easily modify the routine 
  7. #                PrintDocument to support any additions to the PageSetup and Print
  8. #                dialogs that an application may use.
  9. #                At present there is support for the ImageWriter and LaserWriter
  10. #                In the future there will be support for the StyleWriter, Personal
  11. #                LaserWriter LS etc. Watch for new revs.
  12. #
  13. #            DoOrientation        (Select Portrait or landscape)
  14. #            DoPopUp                (Select non-standard popup item)
  15. #            DoRanScale            (Scale randomly with range)
  16. #            SelectScale            (Scale with any list of scale values)
  17. #            DoCheckBox            (Select random checkboxes)
  18. #            PrintPage            (Prints How ever many pages specified)
  19. #            InitLaserGlobals    (Initializes the globals for the LaserWriter)
  20. #            InitImageGlobals    (Initializes the globals for the LaserWriter)
  21. #            PrintDocument        (The control-Selects all options on PageSetup and Print Dialog)
  22. #
  23. #     Copyright Apple Computer, Inc. 1985-1992
  24. #    All rights reserved
  25. #=========================================================================
  26. #     OYG    3/13/92        Created version 1.0
  27. ##########################################################################
  28. Libraries 'Controls.lib','ShimSquad.lib';
  29.  
  30.  
  31. ##########################################################################
  32. #                    DoOrientation(OrientLoc,Orientation)
  33. #=========================================================================
  34. #     Author:            O. Güracar
  35. #    Description:    This task selects which way the paper will be printed 
  36. #                    (Landscape or portrait). You just need to pass the     
  37. #                    location of the Portrait control and which control to 
  38. #                     choose.    NOTE:The task needs the Portrait control
  39. #                    location to find both controls.
  40. #    Parameters:        OrientLoc - the relative location of Portrait control
  41. #                    Orientation - Which control to choose
  42. #                                  "L" for Lanscape "P" for Portrait
  43. #=========================================================================
  44. #    Example:        DoOrientation({122,169},"L");
  45. #=========================================================================
  46. #    History:
  47. #    OYG        3/30/92        Created 
  48. ##########################################################################
  49. Task DoOrientation(OrientLoc,Orientation)
  50. begin
  51. Global PrinterName;
  52.     if (PrinterName = "")
  53.         Global PrinterName:="unnamed Printer";
  54.     if (Orientation = "L")
  55.     begin
  56.         MoveRelativeToWindow((OrientLoc[1]+40),OrientLoc[2]);#Select Landscape
  57.         click;
  58.         LogStr("{PrinterName}-••Selected LandScape orientation for {PrinterName}••");
  59.     end;
  60.     if (Orientation = "P")
  61.     begin
  62.         MoveRelativeToWindow(OrientLoc[1],OrientLoc[2]);#Select Portrait
  63.         click;
  64.         LogStr("{PrinterName}-••Selected Portrait orientation for {PrinterName}••");
  65.     end;
  66.     if (Orientation <>"L" and Orientation <>"P") begin
  67.     LogStr('No Orientation selected');
  68.     end;
  69. end;
  70.  
  71. ##########################################################################
  72. #                            DoCheckBox(CheckBoxList)
  73. #=========================================================================
  74. #    Author:            O. Güracar
  75. #    Description:    This task unselects all checkboxes and then randomly 
  76. #                    selects the checkboxes passed in the list CheckBoxList
  77. #    Parameters:        CheckBoxList - a list of checkbox names to be selected
  78. #                                    randomly.
  79. #                    ex:MyCheckBoxList:={'Font Substitution?','Text Smoothing?'};
  80. #=========================================================================
  81. #    Example:        DoCheckBox(MyCheckBoxList);
  82. #=========================================================================
  83. #    History:
  84. #    OYG        3/30/92        Created 
  85. ##########################################################################
  86. Task DoCheckBox(CheckBoxList) begin
  87. Global PrinterName;
  88.  
  89.     CheckBoxMax:=(card CheckBoxList);        #How many check boxes in the list
  90.     CheckHowMany:=random(1,CheckBoxMax);    #gets a random number of check boxes to check 
  91.     
  92.     for j:=1 to CheckBoxMax do    #loop to UnSelect all check boxes
  93.     begin
  94.         
  95.         CheckBoxItem:=CheckBoxList[j];
  96.         if (match[checkbox t: "{CheckBoxItem}" w:[window o:1] s:{1,1}]!)
  97.         begin
  98.             Select [checkbox t: "{CheckBoxItem}"];    #UnSelect CheckBox
  99.         end;
  100.     end;
  101.     
  102.     for i:=1 to CheckHowMany do #loop to Select random check boxes
  103.     begin
  104.         CheckBoxItemNum:=random(1,CheckBoxMax);
  105.         CheckBoxName:=CheckBoxList[CheckBoxItemNum];
  106.         if (match[checkbox t: "{CheckBoxName}" w:[window o:1] s:{0,1}]!)
  107.         begin
  108.             Select [checkbox t: "{CheckBoxName}"];    #Selects CheckBox
  109.             LogStr("{PrinterName}-••Selected {CheckBoxName}••");
  110.         end;
  111.         else
  112.         begin
  113.         end;
  114.     end;
  115. end;
  116. ##########################################################################
  117. #                            DoRadioButton(RadioButt)
  118. #=========================================================================
  119. #    Author:            O. Güracar
  120. #    Description:    This task selects random radio buttons that are passed
  121. #                    in as a list. The routine selects one radio buttons 
  122. #                    randomly.
  123. #    Parameters:        RadioButt - List of radio buttons to choose from.
  124. #=========================================================================
  125. #    Example:        DoRadioButton(RadioButt);
  126. #=========================================================================
  127. #    History:
  128. #    OYG        5/6/92        Created 
  129. ##########################################################################
  130. task DoRadioButton(RadioButt)
  131. begin
  132. Global PrinterName;
  133.     MaxRadioNum:=(Card RadioButt);
  134.     WhichRadio:=random(1,MaxRadioNum);
  135.     radioItem:=RadioButt[WhichRadio];
  136.     SelectRadioButton("{radioItem}");
  137.     LogStr("{PrinterName}-••Selected radio button {radioItem}••");
  138. end;
  139.     
  140. ##########################################################################
  141. #                    DoPopUp(PopUpControlName,PopUpList,PopUpArray)
  142. #=========================================================================
  143. #    Author:            O. Güracar
  144. #    Description:    This task Resets the popup to the first item in the list
  145. #                    and then selects the chosen item from a non-standard Popup.
  146. #    Parameters:        PopUpControlName - Name of Control popup.
  147. #                    PopUpList - List of names and the position in the list
  148. #                                of Items from popup.
  149. #                    PopUpArray - List of PopUpList
  150. #                    ex: Color:={{'Black & White',0},{'Gray',1}};    
  151. #                    
  152. #                    
  153. #=========================================================================
  154. #    Example:        DoPopUp("Paper:",Paper[pItem],Paper);
  155. #=========================================================================
  156. #    History:
  157. #    OYG        3/30/92        Created 
  158. ##########################################################################
  159. Task DoPopUp(PopUpControlName,PopUpList,PopUpArray) begin
  160. Global PrinterName;
  161.  
  162. if ((Card PopUpArray)=1)
  163.     PopUpListMax:=1;
  164. else
  165.     PopUpListMax:=(Card PopUpArray)-1;
  166.     PopUpItemName:=PopUpList[1];
  167.     PopUpNumber:=PopUpList[2];
  168.  
  169. if (match [control t:"{PopUpControlName}" e:true]!)
  170. begin    
  171.     while not match [control t:"{PopUpControlName}" s:{0,PopUpListMax}]!
  172.         begin
  173.             z:= match[control t: "{PopUpControlName}" s:{0,PopUpListMax}];
  174.             LogStr(" {PopUpControlName},{PopUpItemName},{PopUpNumber},{PopUpListMax}");
  175.             select [control t: "{PopUpControlName}"];
  176.             DoPressMouse();                                
  177.             wait(1);                                        #Delay for PopUp to appear
  178.             MoveMouse(0,-16,0,0);                            #Scroll Up PopUp list by one item
  179.             wait(1);                                        #Delay for PopUp to appear
  180.             DoReleaseMouse();    #Release the Mouse to select
  181.         end;
  182.     select [control t: "{PopUpControlName}"];
  183.     ItemSelection:=16*PopUpNumber;                        #16 * Displacement to next popup item
  184.     DoPressMouse();                            
  185.     wait(1);                                            #Delay for PopUp to appear
  186.     MoveMouse(0,ItemSelection,0,0);                        #Scroll Up PopUp list by PopUpList
  187.     wait(1);                                            #Delay for PopUp to appear
  188.     DoReleaseMouse("{PrinterName}-••Selected PopUp {PopUpItemName}••");    #Release the Mouse to select
  189. end;
  190. else
  191. LogStr("{PrinterName}-••PopUp menu {PopUpControlName} is disabled••");
  192. end;
  193. ##########################################################################
  194. #                            DoRanScale(ScaleFieldLoc,lower,upper)
  195. #=========================================================================
  196. #    Author:            O. Güracar
  197. #    Description:    This task generates a random number for the scale text
  198. #                    field.
  199. #    Parameters:        ScaleFieldLoc - value for the relative location of middle of
  200. #                    Text Edit field. {Must be in array with curly brackets}
  201. #                    lower - the lower bound for the random number
  202. #                            the default is 5
  203. #                    upper - the upper bound for the random number
  204. #                            the default is 999
  205. #=========================================================================
  206. #    Example:        DoRanScale({122,169},9,100);
  207. #=========================================================================
  208. #    History:
  209. #    OYG        3/30/92        Created 
  210. ##########################################################################
  211. Task DoRanScale(ScaleFieldLoc,lower:=5,upper:=999) begin
  212. Global PrinterName;
  213.     
  214.     ran:=Random(lower,upper);
  215.     MoveRelativeToWindow(ScaleFieldLoc[1],ScaleFieldLoc[2]);                #Move to Scale text field]
  216.     doubleClick;
  217.     TypeStr("{ran}");                        #Places random number in scale field
  218.     LogStr("{PrinterName}-••Selected scale:{ran}••");
  219.     MoveRelativeToWindow(ScaleFieldLoc[1],ScaleFieldLoc[2]);                #Move to Scale PopUp
  220.     doubleClick;
  221.     
  222. end;    
  223.  
  224. ##########################################################################
  225. #                            SelectScale(ScaleFieldLoc,Scale)
  226. #=========================================================================
  227. #    Author:            O. Güracar
  228. #    Description:    This task sets the scale in the scale text edit field
  229. #                    the scale is stored in a list and the individual items 
  230. #                    are passed in "scale" 
  231. #    Parameters:        ScaleFieldLoc - value for the relative location of middle of
  232. #                    Text Edit field. {Must be in array with curly brackets}
  233. #                    Scale - the scale to be selected
  234. #=========================================================================
  235. #    Example:        SelectScale({122,169},73);
  236. #=========================================================================
  237. #    History:
  238. #    OYG        3/30/92        Created 
  239. ##########################################################################
  240. Task SelectScale(ScaleFieldLoc,Scale:=100) begin
  241. Global PrinterName;
  242.  
  243.     MoveRelativeToWindow(ScaleFieldLoc[1],ScaleFieldLoc[2]);                #Move to Scale text field]
  244.     doubleClick;
  245.     TypeStr("{Scale}");                        #Places predetermined number in scale field
  246.     LogStr("{PrinterName}-••Selected scale:{Scale}% ••");
  247.     MoveRelativeToWindow(ScaleFieldLoc[1],ScaleFieldLoc[2]);                #Move to Scale PopUp
  248.     doubleClick;
  249.     
  250. end;    
  251.  
  252.  
  253. ##########################################################################
  254. #                            PrintPage(NumOfPages)
  255. #=========================================================================
  256. #    Author:            O. Güracar
  257. #    Description:    This task prints pages and then reselects Page Setup 
  258. #                    dialog.
  259. #    Parameters:        NumOfPages - how many pages to print default to ALL
  260. #=========================================================================
  261. #    Example:        PrintPage(2);
  262. #=========================================================================
  263. #    History:
  264. #    OYG        3/30/92        Created 
  265. ##########################################################################
  266. Task PrintPage(NumOfPages:="1") 
  267. begin
  268. Global PrinterName,DocName;
  269.     If (NumOfPages = "all")begin
  270.         SelectButton("Print");
  271.         LogStr("{PrinterName}-••Printing {NumOfPages} pages••");
  272.         end;
  273.     Else
  274.         begin
  275.         select[radioButton t:"From:"];
  276.         if (PrinterName = "ImageWriter")
  277.             Type k:{tabKey};
  278.         TypeStr("1");
  279.         Type k:{tabKey};
  280.         TypeStr("{NumOfPages}");
  281.         SelectButton("Print");        #Should Be set to PRINT for test
  282.         LogStr("{PrinterName}-••Printing {NumOfPages} pages••");
  283.         end;
  284. end;
  285. ##########################################################################
  286. #                            InitLaserGlobals()
  287. #=========================================================================
  288. #    Author:            O. Güracar
  289. #    Description:    initializes the globals for the controls for the 
  290. #                    LaserWriter.
  291. #    Parameters:        None 
  292. #=========================================================================
  293. #    Example:        InitLaserGlobals();
  294. #=========================================================================
  295. #    History:
  296. #    OYG        5/6/92        Created 
  297. ##########################################################################
  298. task InitLaserGlobals()
  299. begin
  300. Global PrinterName:="LaserWriter";
  301. Global CheckBoxOne:={'Font Substitution?','Text Smoothing?','Graphics Smoothing?','Faster Bitmap Printing?'};
  302. Global CheckBoxTwo:={'Flip Horizontal','Flip Vertical','Invert Image','Precision Bitmap Alignment (4% Reduction)','Unlimited Downloadable Fonts in a Document'};
  303. Global ScaleBox:={145,80}; # Replace with value 
  304. Global POrientationLoc:={80,140}; # Replace with value 
  305. Global    Orientation:={"P","L"};
  306.  
  307. #Print Dialog
  308. Global RadioPrint:={'Black & White','Color/Grayscale'};
  309. end;
  310. ##########################################################################
  311. #                            InitImageGlobals()
  312. #=========================================================================
  313. #    Author:            Osman Güracar
  314. #    Description:    initializes the globals for the controls for the 
  315. #                    Imagewriter.
  316. #    Parameters:        None 
  317. #=========================================================================
  318. #    Example:        InitImageGlobals();
  319. #=========================================================================
  320. #    History:
  321. #    OYG        5/6/92        Created 
  322. ##########################################################################
  323. task InitImageGlobals()
  324. begin
  325. Global PrinterName:="ImageWriter";
  326. Global CheckBoxOne:={"Tall Adjusted","50% Reduction","No Gaps Between Pages"};
  327. Global CheckBoxTwo:={};
  328.  
  329. Global POrientationLoc:={30,120}; # Replace with value 
  330. Global    Orientation:={"P","L"};
  331. Global ScaleBox:={};
  332.  
  333. #Print Dialog
  334. Global RadioPrint:={'Best','Faster','Draft'};
  335. end;
  336. ##################################################################################################
  337. #    Add any globals for other printer drivers here as "task Init(DriverName)Globals and then make
  338. #    a call to it as in PrintDocument.
  339. ##################################################################################################
  340. ##########################################################################
  341. #                            PrintDocument(PrinterName)
  342. #=========================================================================
  343. #    Author:            O. Güracar
  344. #    Description:    This script randomly selects the items on the Page Setup
  345. #                    and Print dialog and then prints a specified number of 
  346. #                    pages. Feel free to customize the InitGlogals routines 
  347. #                    above to if the added functionality in the specific 
  348. #                    application you are testing.
  349. #    Parameters:        PrinterName - This is not the name you gave the printer
  350. #                    but the type (ex "LaserWriter" or "ImageWriter")
  351. #=========================================================================
  352. #    Example:        PrintDocument(PrinterName);
  353. #=========================================================================
  354. #    History:
  355. #    OYG        5/6/92        Created 
  356. #    Future    Support for the stylewriter,Personal LWLS.
  357. ##########################################################################
  358.  
  359. task PrintDocument(PrinterName)
  360. begin
  361. Global CheckBoxOne,CheckBoxTwo,POrientationLoc,Orientation,ScaleBox,RadioPrint;
  362. Global NumOfPages:=1;
  363. if (PrinterName = "ImageWriter")
  364. begin
  365.     InitImageGlobals();                #Initialize globals for imagewriter
  366. end;
  367. if (PrinterName = "LaserWriter")
  368. begin
  369.     InitLaserGlobals();#Initialize globals for imagewriter
  370. end;
  371. OrientItem:=random(1,2);
  372. #####  Add any call to other drivers here   ##########
  373. if (match[menuitem t:/Page Setup?/ m:'File'])
  374.     begin
  375.         select [menuitem t: /Page Setup?/ m: 'File'];
  376.         DoCheckBox(CheckBoxOne);
  377.         DoOrientation(POrientationLoc,Orientation[OrientItem]);#Put "P" or "L"
  378.         if (match[button t:"Options"]!)
  379.         begin
  380.             select[button t:"Options"];
  381.             if (CheckBoxTwo)
  382.             begin
  383.                 DoCheckBox(CheckBoxTwo);
  384.                 select[button t:"OK"];
  385.             end;
  386.         end;
  387.         if (ScaleBox)
  388.         begin
  389.             DoRanScale(scaleBox,25,200);
  390.         end;
  391.         if (match[button t:"OK"]!)
  392.             select[button t:"OK"];
  393.         else
  394.         begin
  395.             type k:{ReturnKey};
  396.         end;
  397.     end; #End PageSetup IF
  398. if match[menuitem t:"Print…" m:'File']!
  399.     select [menuitem t: "Print…" m: 'File'];
  400. if match[menuitem t:"Print..." m:'File']!
  401.     select [menuitem t: "Print..." m: 'File'];
  402. DoRadioButton(RadioPrint);
  403. PrintPage(NumOfPages);
  404. end;    #End PrintDocument